#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;

bool comp(char *a, char *b)
{
    while (*a && *b) {
        if (*a != *b)
            return false;
        a++;
        b++;
    }
    if (!*b) return true;
    if (!*a) return false;
}

class Solution1 {
    public:
        char *strStr(char *haystack, char *needle) {
            if (!*needle) return haystack;
            while (*haystack) {
               char *p = haystack;
               if (comp(p, needle))
                   return p; 
               haystack++; 
            }
            return NULL;
        }
};

class Solution {
    public:
        char *strStr(char *haystack, char *needle) {
            if (!*needle) return haystack;
            while (*haystack) {
               char *p = haystack;
               char *pDst = needle;
               while(*p && *pDst && *p == *pDst) {
                    p++;
                    pDst++;
               }
               if (!*pDst) return haystack;
               haystack++; 
            }
            return NULL;
        }
};

int main(int argc, char **argv)
{
    Solution mySolution;
    char src[] = "This is a test";
    char *test = NULL;
    char *test2 = NULL;
    char dst[] = "isa";
    char *ans = mySolution.strStr(src, test);
    if (ans) cout << ans << endl;
    else cout <<" Could not find" << endl;
}
